package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName: OssConfiguration
 * Package: com.sky.config
 * Description:
 * 配置类，用于创建AliOssUtil对象
 * @Author 龙培
 * @Create 2025/3/1 22:32
 * @Version 1.0
 */
@Configuration
@Slf4j
public class OssConfiguration {
    @Bean
    @ConditionalOnMissingBean // 当容器中没有AliOssUtil对象时，才会创建
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties) {//使用参数注入AliOssProperties对象，跟使用@Autowired效果一样
        log.info("创建AliOssUtil对象");
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }

}
